var status = 1;
var jName = getCookie('Jname');
//我的权限数组
var arrayTitle = new Array;
$(document).ready(function() {
findMyCatalogue();
loadMyEssay(status);
});


function loadMyEssay(status) {
	findMyCatalogue();
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/paramSetting/limitDaysParams?status=" + status,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				$.each(data.data, function(i, n) {
					var id = n.id;
					var status = "";
					var thislist = "";
					if(n.status == 1) {
						status = "可用";
					} else if(n.status == 2) {
						status = "已禁用";
					}
					thislist +=
						'<tr class="footable-even" style="display: table-row;">' +
						'<td class="footable-visible">' + n.id + '</td>' +
						'<td class="footable-visible">' + n.limitDays + '</td>' +
						'<td class="footable-visible">' + n.interestPercent + '</td>' +
						'<td class="footable-visible">' + n.overduePercent + '</td>' +
						'<td class="footable-visible">' + status + '</td>' +
						'<td class="footable-visible footable-last-column">'
					if(status == '已禁用') {
						thislist += " <a hidden=\"hidden\" name=\"取消禁用\" class=\"btn btn-info btn-xs\" href=\"javascript:;\" onclick=\"thisUsing(" + id + ",1)\">取消禁用</a>\n"

					} else if(status == '可用') {
						thislist += " <a hidden=\"hidden\" name=\"禁用\" class=\"btn btn-warning btn-xs\" href=\"javascript:;\"  onclick=\"thisStopUsing(" + id + ",2)\"> 禁用</a>\n" +
							"  <a hidden=\"hidden\" name=\"修改\" class=\"btn btn-primary btn-xs\"  href=\"modify_param_setting.html?id=" + id + "\">修改</a>&nbsp;\n" +
							"  <a hidden=\"hidden\" name=\"删除\"  class=\"btn btn-primary btn-xs\"  onclick=\"thisDelete(" + id + ")\">删除</a>&nbsp;\n"
					}
					'</tr>';
					$('#thislist').append(thislist);

				});
				$.each(arrayTitle, function(i, k) {
					$('a[name="' + k + '"]').attr("hidden", true).attr("class", "btn btn-primary btn-xs");
					$('a[data="添加利率配置"]').attr("class", "btn btn-sm btn-primary");
				});
				
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;

				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}

			} else {
				if(data.msg != '空数据') {
					alert(data.msg)
				} else {
					$('#thiscount').text(0);
				}
			}
		},
		error: function() {
			alert("error");
		}
	});

}

/**
 * 删除
 */
function thisDelete(id) {
	if(confirm("您确定要删除该贷款类型吗？")) {
		$.ajax({
			url: urlcore + "/api/paramSetting/delete?id=" + id,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					window.location.reload();
				}
			},
			error: function() {
				/* Act on the event */
				alert("error");
			}
		});
	}

}

function selectStatus(status) {
	loadMyEssay(status);
}

function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
		" " + date.getHours() + seperator2 + date.getMinutes() +
		seperator2 + date.getSeconds();

}

/*
 * 禁用
 */
function thisStopUsing(id, type) {
	if(confirm("您确定要停用该贷款类型吗？")) {
		$.ajax({
			url: urlcore + "/api/paramSetting/stopUsing?id=" + id + "&type=" + type,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					window.location.reload();
				}
			},
			error: function() {
				/* Act on the event */
				alert("error");
			}
		});
	}
}

/*
 * 取消禁用
 */

function thisUsing(id, type) {
	$.ajax({
		url: urlcore + "/api/paramSetting/stopUsing?id=" + id + "&type=" + type,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				window.location.reload();
			}
		},
		error: function() {
			/* Act on the event */
			alert("error");
		}
	});
}

function findMyCatalogue() {
	$.ajax({
		url: urlcore + "/api/roleThirdCatalogue/findAllByUser?secondTitle=" + jName,
		type: "GET",
		dataType: 'json',
		async: false,
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				$.each(data.data, function(i, n) {
					arrayTitle.push(n.thirdCatalogue.title);
				});
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}
	});
}